/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package etherblocks.game.entitysystem.systems;

import com.jme3.scene.Node;
import etherblocks.engine.objects.ModelObject;
import etherblocks.game.entitysystem.*;
import etherblocks.game.entitysystem.components.*;

/**
 *
 * @author Carl
 */
public class RemoveEntitySystem extends ModelObjectSystem{    

    public RemoveEntitySystem(Node rootNode){
        super(rootNode);
    }
    
    @Override
    public void onNextFrameCalculation(EntityMap entityMap, float lastTimePerFrame){
        for(Entity entity : entityMap.getEntities(RemovedComponent.class)){
            ModelObject modelObject = getModelObject(entity);
            if(modelObject != null){
                modelObject.removeFromParent();
            }
            entityMap.removeEntity(entity.getID());
        }
        for(Entity entity : entityMap.getEntities(RemoveRequestComponent.class)){
            entity.setComponent(new RemovedComponent());
        }
    }
}
